home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_01_07 / 1n07024a < prev    next >
Text File  |  1990-11-03  |  8KB  |  251 lines

  1.  
  2. /*
  3.  *  To link the VESAINFO program, issue the following command:
  4.  *  LINK VESADEMO VESA;
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10.  
  11. #include "vesa.h"
  12. #include "vesa.fd"
  13.  
  14. extern  int main(int argc,char * *argv);
  15. extern  void DisplaySVGAInfo(struct vga_info_block *vesa_info);
  16. extern  void DisplaySVGAModeInfo(short svga_mode,
  17.              struct mode_info_block *mode_info,short vesa_ver);
  18. extern  void DisplayAttributes(struct attr_list *attr_ptr,
  19.              short attr_count,short source_info);
  20. extern  void strcpy_from_far_away(char *here_str,char far *far_str);
  21.  
  22.  
  23. struct attr_list {
  24.    short attr_val;      /* Bitmask value for "AND" comparison  */
  25.    char *attr_true;     /* Display this string if masked true  */
  26.    char *attr_false;    /* Display this string if masked false */
  27.       } AttrList;
  28.  
  29. struct attr_list mode_attrs[] = {
  30.    { SVGA_MODE_HARDWARE,
  31.        "Mode is supported in hardware",
  32.        "Mode is not supported in hardware" },
  33.    { SVGA_MODE_EXTENDED,
  34.        "Extended mode information is available",
  35.        "Extended mode information is not available" },
  36.    { SVGA_MODE_BIOS,
  37.        "Output functions are supported by BIOS",
  38.        "Output functions are not supported by BIOS" },
  39.    { SVGA_MODE_COLOR,
  40.        "This is a color mode",
  41.        "This is a monochrome mode" },
  42.    { SVGA_MODE_GRAPHICS,
  43.        "This is a graphics mode",
  44.        "This is a text mode" }
  45.    };
  46.  
  47. struct attr_list win_attrs[] = {
  48.    { SVGA_WIN_SUPPORTED,
  49.        "Window is supported",
  50.        "Window is not supported" },
  51.    { SVGA_WIN_READABLE,
  52.        "Window is readable",
  53.        "Window is not readable" },
  54.    { SVGA_WIN_WRITEABLE,
  55.        "Window is writeable",
  56.        "Window is not writeable" },
  57.    };
  58.  
  59. #define NUM_MODE_ATTRS (sizeof(mode_attrs) / sizeof(AttrList))
  60. #define NUM_WIN_ATTRS  (sizeof(win_attrs) / sizeof(AttrList))
  61.  
  62. char *model_names[] = {
  63.    "Text mode", "CGA graphics", "Hercules graphics",
  64.    "4-plane planar", "Packed pixel", "non-chain 4, 256 color"
  65.    };
  66.  
  67. #define NOT_AVAILABLE "Not available (needs VESA v1.1)"
  68.  
  69.  
  70. int main(argc, argv)
  71. int argc;
  72. char **argv;
  73. {
  74.    VgaInfoBlock *vesa_info;
  75.    ModeInfoBlock *mode_info;
  76.    short far *temp_mode_ptr;
  77.    short VgaStat;
  78.    short num_blocks;
  79.  
  80.    printf("VESA Information Reporter v1.30, by Victor R. Volkman\n");
  81.  
  82.    /* If either of the first two "sizeof" tests fail, then your compiler
  83.       has added filler bytes between the struct fields.  Recompile with
  84.       appropriate structure packing option */
  85.  
  86.    if (sizeof(VgaInfoBlock) != SVGA_INFO_BLOCK)
  87.       {
  88.       printf("error:  VgaInfoBlock must be %d bytes!\n",SVGA_INFO_BLOCK);
  89.       exit(-1);
  90.       }
  91.    if (sizeof(ModeInfoBlock) != SVGA_INFO_BLOCK)
  92.       {
  93.       printf("error:  ModeInfoBlock must be %d bytes!\n",SVGA_INFO_BLOCK);
  94.       exit(-1);
  95.       }
  96.  
  97.    if ((vesa_info=(VgaInfoBlock *) calloc(1,sizeof(VgaInfoBlock))) == NULL)
  98.       {
  99.       printf("error:  unable to allocate SVGA Info Block\n");
  100.       exit(-1);
  101.       }
  102.    if ((mode_info=(ModeInfoBlock *) calloc(1,SVGA_INFO_BLOCK)) == NULL)
  103.       {
  104.       printf("error:  unable to allocate Mode Info Block\n");
  105.       exit(-1);
  106.       }
  107.  
  108.    printf("Testing for presence of VESA support...\n");
  109.    VgaStat = GetSVGAInfo(vesa_info);
  110.    if (VgaStat == ERROR_VESA_NOT_SUPPORTED)
  111.       {
  112.       printf("error: VESA support has not been installed!\n");
  113.       return VgaStat;
  114.       }
  115.    else if (VgaStat == ERROR_VESA_NO_SIGNATURE)
  116.       {
  117.       printf("error: bad VESA signature, VESA Support disabled\n");
  118.       return VgaStat;
  119.       }
  120.  
  121.    DisplaySVGAInfo(vesa_info);
  122.    GetSVGAStateBufferSize(0x0F, &num_blocks);
  123.    printf("Bytes required to save/restore total video state: %d\n",num_blocks*64);
  124.    temp_mode_ptr = vesa_info->VideoModePtr;
  125.  
  126.    while (*temp_mode_ptr != -1)
  127.       {
  128.       GetSVGAModeInfo(*temp_mode_ptr, mode_info);
  129.       DisplaySVGAModeInfo(*temp_mode_ptr, mode_info, vesa_info->VESAVersion);
  130.       temp_mode_ptr++;
  131.       }
  132.  
  133.    free((char *) vesa_info);
  134.    free((char *) mode_info);
  135.    return 0;
  136. }
  137.  
  138.  
  139. void DisplaySVGAInfo(vesa_info)
  140. VgaInfoBlock *vesa_info;
  141. {
  142.    char oem_str[80];
  143.    char total_mem_str[80];
  144.    short far *temp_mode_ptr;
  145.  
  146.    printf("VESA Version Number %d.%02d\n", vesa_info->VESAVersion / 256,
  147.            vesa_info->VESAVersion % 256);
  148.  
  149.    /* Fetch string regardless of near/far memory model */
  150.    strcpy_from_far_away(oem_str, vesa_info->OEMStringPtr);
  151.    printf("SuperVGA OEM manufacturing code: \"%s\".\n", oem_str);
  152.    printf("SuperVGA Capabilities: %08lXh (normally 00000000h)\n", vesa_info->capabilities);
  153.  
  154.    if (vesa_info->VESAVersion >= VESA_VER_110)
  155.       sprintf(total_mem_str, "%dK bytes\n", vesa_info->TotalMemory * 64);
  156.    else
  157.       strcpy(total_mem_str, NOT_AVAILABLE);
  158.  
  159.    printf("Total Memory on VGA card:  %s\n", total_mem_str);
  160.    printf("Video Mode List:  ");
  161.    temp_mode_ptr = vesa_info->VideoModePtr;
  162.    while (*temp_mode_ptr != -1)
  163.       printf("%03Xh ",*temp_mode_ptr++);
  164.    printf("\n");
  165. }
  166.  
  167.  
  168. void DisplaySVGAModeInfo(svga_mode,mode_info,vesa_ver)
  169. short svga_mode;
  170. ModeInfoBlock *mode_info;
  171. short vesa_ver;
  172. {
  173.    char model_str[40];
  174.    char image_page_str[80];
  175.    short mode_no;
  176.  
  177.    printf("\nReport for mode %03Xh:\n", svga_mode);
  178.  
  179.    printf("\tMode Attributes: %04Xh\n",mode_info->ModeAttributes);
  180.    DisplayAttributes(mode_attrs,NUM_MODE_ATTRS,mode_info->ModeAttributes);
  181.    printf("\tWindow A Attributes:\n");
  182.    DisplayAttributes(win_attrs,NUM_WIN_ATTRS,mode_info->WinAAttributes);
  183.    printf("\tWindow B Attributes:\n");
  184.  
  185.    DisplayAttributes(win_attrs,NUM_WIN_ATTRS,mode_info->WinBAttributes);
  186.    printf("\tWindow Granularity: %dK\n",mode_info->WinGranularity);
  187.    printf("\tWindow Size: %dK\n",mode_info->WinSize);
  188.    printf("\tWindow A Segment: %04Xh\n", mode_info->WinASegment);
  189.    printf("\tWindow B Segment: %04Xh\n", mode_info->WinBSegment);
  190.    printf("\tWindow Function Pointer: %p\n", mode_info->WinFuncPtr);
  191.    printf("\tBytes Per Scan Line: %d\n", mode_info->BytesPerScanLine);
  192.  
  193.    if (mode_info->ModeAttributes & SVGA_MODE_EXTENDED)
  194.       {
  195.       printf("\tExtended mode information:\n");
  196.       printf("\t\tX Resolution: %d\n",mode_info->XResolution);
  197.       printf("\t\tY Resolution: %d\n",mode_info->YResolution);
  198.       printf("\t\tX Char Size: %d pixels\n",mode_info->XCharSize);
  199.       printf("\t\tY Char Size: %d pixels\n",mode_info->YCharSize);
  200.       printf("\t\tNumber of Planes: %d\n",mode_info->NumberOfPlanes);
  201.       printf("\t\tBits per Pixel: %d\n",mode_info->BitsPerPixel);
  202.       printf("\t\tNumber of Banks: %d\n",mode_info->NumberOfBanks);
  203.       mode_no = mode_info->MemoryModel;
  204.       if (mode_no > 0 && mode_no < 6)
  205.          strcpy(model_str,model_names[mode_no]);
  206.       else if (mode_no >= 0x06 && mode_no <= 0x0F)
  207.          strcpy(model_str,"Reserved, to be defined by VESA");
  208.       else
  209.          strcpy(model_str,"To be defined by OEM");
  210.       printf("\t\tMemory Model: %s\n",model_str);
  211.       printf("\t\tBank Size: %dK\n",mode_info->BankSize);
  212.       if (vesa_ver >= VESA_VER_110)
  213.          itoa(mode_info->NumberOfImagePages, image_page_str, 10);
  214.       else
  215.          strcpy(image_page_str, NOT_AVAILABLE);
  216.       printf("\t\tNumber of Image Pages: %s\n",image_page_str);
  217.       }
  218.  
  219.    printf("\n");
  220. }
  221.  
  222.  
  223. void DisplayAttributes(attr_ptr, attr_count, source_info)
  224. struct attr_list *attr_ptr;
  225. short attr_count;
  226. short source_info;
  227. {
  228.    int i;
  229.    char *use_str;
  230.    for (i=0; i<attr_count; i++)
  231.       {
  232.       if (attr_ptr[i].attr_val & source_info)
  233.          use_str = attr_ptr[i].attr_true;
  234.       else
  235.          use_str = attr_ptr[i].attr_false;
  236.  
  237.       printf("\t\t%s.\n",use_str);
  238.       }
  239. }
  240.  
  241.  
  242. /* copy string from far (32-bit) source, regardless of memory model */
  243. void strcpy_from_far_away(here_str,far_str)
  244. char *here_str;
  245. char far *far_str;
  246. {
  247.    while (*far_str)
  248.       *here_str++ = *far_str++;
  249.    *here_str = '\0';
  250. }
  251.